package com.kakarote.admin.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.kakarote.admin.entity.PO.AdminApply;
import com.kakarote.core.servlet.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 应用申请信息表 Mapper 接口
 * </p>
 *
 * @author zhangzhiwei
 * @since 2022-01-07
 */
public interface AdminApplyMapper extends BaseMapper<AdminApply> {

    /**
     * 修改wk_admin_apply表中名字相同，并且比打电话次数大于0的 拨打电话次数
     *
     * @param name   名字
     * @param number 次数
     * @return java.lang.Integer
     */
    @Update("UPDATE `wk_admin_apply` SET `call_number` = call_number - #{number} WHERE name = #{name} and `call_number` > 0")
    Integer updateAdminApplyNumberInfo(String name, Integer number);

    @InterceptorIgnore(tenantLine = "true")
    @Insert("INSERT INTO `wk_admin_apply` (id,name,create_time,create_user_id,update_user_id,update_time,status,call_number,end_time) VALUES " +
            "(#{adminApply.id},#{adminApply.name},#{adminApply.createTime},#{adminApply.createUserId}" +
            ",#{adminApply.updateUserId},#{adminApply.updateTime},#{adminApply.status},#{adminApply.callNumber}" +
            ",#{adminApply.endTime})")
    Integer saveAdminApply(@Param("adminApply") AdminApply adminApply);

    @InterceptorIgnore(tenantLine = "true")
    @Update("UPDATE `wk_admin_apply` SET name = #{adminApply.name},status = #{adminApply.status},end_time = #{adminApply.endTime} WHERE id = #{adminApply.id}")
    Integer updateAdminApplyById(@Param("adminApply") AdminApply adminApply);
}
